package org.jivesoftware.sparkimpl.plugin.alerts;

import java.util.Date;

import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscript;
import org.jivesoftware.sparkimpl.plugin.transcripts.HistoryMessage;

/**
 * 
 * @author byl
 *	
 *	message工具类
 *	
 *
 */
public final class MessageToTranscript {
	
	private MessageToTranscript(Message message){
		messageToTranscript(message);
		
	}
	
	
	/**
	 * 
	 * 把消息(message)体格式 转换成  消息副本(transcrip)格式
	 * 
	 * @param message
	 * @return
	 */
	public static ChatTranscript messageToTranscript(Message message){
		ChatTranscript transcript = new ChatTranscript();
		HistoryMessage history = new HistoryMessage();
        history.setTo(message.getTo());
        history.setFrom(message.getFrom());
        history.setBody(message.getBody());
        Date date = (Date)message.getProperty("date");
        if (date != null) {
            history.setDate(date);
        }
        else {
            history.setDate(new Date());
        }
        transcript.addHistoryMessage(history);
        return transcript;
	}
	

}
